<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>公司用车管理系统 - 登录</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: "Microsoft YaHei", Arial, sans-serif;
            background: linear-gradient(135deg, #183a8a, #1da1e7);
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .login-container {
            background: white;
            padding: 40px;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
            width: 400px;
        }

        .login-header {
            text-align: center;
            margin-bottom: 30px;
        }

        .login-header h1 {
            color: #183a8a;
            font-size: 24px;
            margin-bottom: 10px;
        }

        .login-form {
            display: flex;
            flex-direction: column;
            gap: 20px;
        }

        .form-group {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .form-group label {
            color: #333;
            font-size: 14px;
        }

        .form-group input,
        .form-group select {
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 14px;
            transition: border-color 0.3s;
        }

        .form-group input:focus,
        .form-group select:focus {
            border-color: #1da1e7;
            outline: none;
        }

        .role-selector {
            display: flex;
            gap: 10px;
            margin-bottom: 20px;
        }

        .role-option {
            flex: 1;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 6px;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s;
        }

        .role-option:hover {
            border-color: #1da1e7;
            background: #f8f9fa;
        }

        .role-option.selected {
            border-color: #1da1e7;
            background: #e8f4fc;
        }

        .login-btn {
            background: #1da1e7;
            color: white;
            padding: 12px;
            border: none;
            border-radius: 6px;
            font-size: 16px;
            cursor: pointer;
            transition: background 0.3s;
        }

        .login-btn:hover {
            background: #2176b8;
        }

        .error-message {
            color: #ff4757;
            font-size: 14px;
            text-align: center;
            margin-top: 10px;
            display: none;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <div class="login-header">
            <h1>公司用车管理系统</h1>
            <p>请选择您的身份并登录</p>
        </div>

        <form class="login-form" action="<%=request.getContextPath()%>/LoginServlet" method="post">
            <div class="role-selector">
                <div class="role-option" onclick="selectRole(this, 'driver')">
                    <input type="radio" name="role" value="driver" id="driver" style="display: none;">
                    <label for="driver">司机</label>
                </div>
                <div class="role-option" onclick="selectRole(this, 'driverLeader')">
                    <input type="radio" name="role" value="driverLeader" id="driverLeader" style="display: none;">
                    <label for="driverLeader">司机队长</label>
                </div>
                <div class="role-option" onclick="selectRole(this, 'employee')">
                    <input type="radio" name="role" value="employee" id="employee" style="display: none;">
                    <label for="employee">员工（申请用车）</label>
                </div>
                <div class="role-option" onclick="selectRole(this, 'finance')">
                    <input type="radio" name="role" value="finance" id="finance" style="display: none;">
                    <label for="finance">财务</label>
                </div>
            </div>

            <div class="form-group">
                <label for="username">工号</label>
                <input type="text" id="username" name="username" required placeholder="请输入工号">
            </div>

            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" required placeholder="请输入密码">
            </div>

            <input type="hidden" name="driverInfo" value="driver">
            <button type="submit" class="login-btn">登录</button>
            <div class="error-message" id="error-message"></div>
        </form>
    </div>

    <script>
        function selectRole(element, role) {
            // 移除所有选中状态
            document.querySelectorAll('.role-option').forEach(opt => {
                opt.classList.remove('selected');
            });
            
            // 添加选中状态
            element.classList.add('selected');
            
            // 选中对应的radio
            document.getElementById(role).checked = true;
        }

        // 表单提交验证
        document.querySelector('.login-form').addEventListener('submit', function(e) {
            const role = document.querySelector('input[name="role"]:checked');
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            const errorMessage = document.getElementById('error-message');

            if (!role) {
                e.preventDefault();
                errorMessage.style.display = 'block';
                errorMessage.textContent = '请选择您的身份';
                return;
            }

            if (!username || !password) {
                e.preventDefault();
                errorMessage.style.display = 'block';
                errorMessage.textContent = '请输入用户名和密码';
                return;
            }

            errorMessage.style.display = 'none';
        });
    </script>
</body>
</html> 